const app = getApp()
import util from '../../../utils/util'
import {
  GetGriderList,
  GetGriderHome,
  GetGridMuse,
  GetIsseuChuLi
} from '../../../config/api'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    curIndex:0,
    grider_storge:'',
    grider_id:'',
    grider_list:[],
    grid_nums:'',
    grid_manage:[],
    data:[],
    isEmpty:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let grider_storge = wx.getStorageSync('grider')
    //grider_storge={id:8}
    this.setData({
      grider_storge: grider_storge  // 正式打开
    })
    this.GetIsseuChuLi();
    //this.getGriderList();
  },
//下级处理首页
  GetIsseuChuLi(){
    let that = this;
    let id = this.data.grider_storge.id;
    util.apiRequest(GetIsseuChuLi,{
      vollege_id:app.globalData.vollege_id,
      id:id
    },null).then(r => {
      console.log('下级处理首页',r)
      if(r.data.code==0){
        wx.showToast({
          title: r.data.info,
          icon: 'none',
          duration:2000
        })
        that.setData({
          isEmpty: true
        })
        return false;
      }
      that.setData({
        data: r.data.data
      })
    })
  },


  getGriderList(){ // 获取网格员列表
    let that = this;
    let id = this.data.grider_storge.id;
    util.apiRequest(GetGriderList,{id:id},null).then(r => {
      console.log('网格员列表',r)
      that.setData({
        grider_list: r.data.data.data,
        grider_id: r.data.data.data[0].id
      })
      that.getGridManage()
      that.getGriderData()
    })
  },

  //获取网格管理菜单
  getGridManage() {
    let that = this;
    var id = that.data.grider_id
    var vollege_id = that.data.grider_storge.vollege_id
    util.apiRequest(GetGridMuse, { id: id, vollege_id: vollege_id }, null).then(r => {
      console.log('网格管理菜单：', r)
      that.setData({
        grid_manage: r.data.data
      })
    })
  },

  getGriderData(){ // 获取网格员数据个数
    let that = this;
    util.apiRequest(GetGriderHome, { id: that.data.grider_id}, null).then(r => {
      console.log('1网格员数据数量：', r)
      that.setData({
        grid_nums: r.data.data 
      })
    })
  },

  onSelectGrider(e){
    let id = e.currentTarget.dataset.id;
    let index = e.currentTarget.dataset.index;
    this.setData({
      grider_id: id,
      curIndex:index
    })
    this.getGridManage()
    this.getGriderData()
  },

  toEventList(e) { // 网格长/网格员跳转事件列表
    let cat_id = e.currentTarget.dataset.cat_id;
    let type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/grid/griderIsseuEventList/griderIsseuEventList',
    })
  },

  toEventList1(e) { // 网格长/网格员跳转事件列表
    let cat_id = e.currentTarget.dataset.cat_id;
    let type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/grid/getPhoneAppealList/getPhoneAppealList',
    })
  },

  toEventList2(e) { // 网格长/网格员跳转事件列表
    let cat_id = e.currentTarget.dataset.cat_id;
    let type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/pages/grid/getIsseuSjrwList/getIsseuSjrwList',
    })
  },
  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})